package com.smart.base.login.controller;

import com.alibaba.fastjson.JSONObject;
import com.smart.common.smart.ImageCode;
import com.smart.common.smart.controller.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Arnold.zhao <a href="mailto:13949123615@163.com"/>
 * @create 2018-10-20 10:13
 */
@Controller
@RequestMapping("/login")
public class LoginController {


    @RequestMapping("")
    public String execute(HttpServletRequest request,HttpServletResponse response){

        return "login/login";
    }

    @RequestMapping("home")
    public String systemHome(HttpServletRequest request,HttpServletResponse response){

        return "systemHome/systemHome";
    }



    @RequestMapping("test")
    @ResponseBody
    public Object test(HttpServletRequest request,HttpServletResponse response){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("操作成功");
        jsonResult.setStatus("1");
        jsonResult.setSuccess(true);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("数据","对应的数据值");
        jsonResult.setData(jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("****",jsonResult);
        System.out.printf(jsonObject1.toString());
        return jsonResult;
    }

    @RequestMapping("imgCode")
    public void imgCode(HttpServletRequest request, HttpServletResponse response){
        response.setContentType("image/jpeg");
        //禁止图像缓存。
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        ImageCode vCode = new ImageCode();
        request.getSession().setAttribute("imageCode", vCode.getCode());
        try {
            vCode.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
